// ID: B0201
package git.bankview.wl.servlet;

import java.io.*;
import java.util.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import org.apache.log4j.Logger;

import laya.util.*;

import git.bankview.sl.Globals;
import git.bankview.sl.report.ReportParameter;
import git.bankview.sl.report.ReportSchd;
import git.bankview.sl.report.SchdUtil;

/**
 *
 * @version v0.00.0024
 * @author BJ L.Shuang(2004/05/07)
 */
public class SchdDownloadServlet extends SingleFileDownloadServlet
{
	private static Logger log = Logger.getLogger(SchdDownloadServlet.class);

	/**
	 *
	 * @param request Request
	 * @param response Response
	 * @see #doGet(HttpServletRequest,HttpServletResponse)
	 */
	protected File resolveRequestedFile(HttpServletRequest request)
		throws ServletException, IOException
	{
		String oSrcPath = request.getRequestURI();
		log.debug("handle report download request: " + oSrcPath);
		int extIdx = oSrcPath.lastIndexOf(".");
		String schdexport = oSrcPath.substring(extIdx + 1).toUpperCase();
		String schdid = oSrcPath.substring(extIdx - 8, extIdx);
		try
		{
			ReportSchd schd = SchdUtil.getReportSchdById(Integer.parseInt(schdid));
			return SchdUtil.getReportExportFile(schd);
		}
		catch(Exception e)
		{
			log.warn("handle report download request error (" + oSrcPath + ")", e);
			throw new IOException("handle report download request error (" + oSrcPath + ")");
		}
	}
}
